package www.bplead.com.mydemo.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import www.bplead.com.controller.action.BaseAction;
import www.bplead.com.controller.action.user.entity.UserInfo;
import www.bplead.com.mydemo.R;

/**
 * Created by wangyangzi on 2016/10/16.
 */
public class ImageGridAdapter extends BaseAdapter {
    private Context context;
    private List<Bitmap> bitmapList;

    public ImageGridAdapter(Context context,List<Bitmap> bitmapList){
        this.context = context;
        this.bitmapList = bitmapList;
    }

    @Override
    public int getCount() {
        return bitmapList.size();
    }

    @Override
    public Object getItem(int position) {
        return bitmapList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Bitmap bitmap = (Bitmap) getItem(position);

        ViewHolder viewHolder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.image_item,null);
            viewHolder = new ViewHolder();
            viewHolder.image = (ImageView) convertView.findViewById(R.id.image);

            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.image.setImageBitmap(bitmap);

        return convertView;
    }

    public static class ViewHolder{
        ImageView image;
    }
}
